const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
var globalConfig = require("./globalConfig.json");

module.exports = {
    mode: "none",
    // devtool: 'cheap-module-source-map',
    /*入口*/
    entry: {
        app: [
            // path.join(__dirname, 'src/pages/ruijing/index/IndexPage.js'),
            path.join(__dirname, "src/pages/ruijing/search/SearchProduct.js")
            // path.join(__dirname, 'src/pages/ruijing/SearchResults/index.js'),
            // path.join(__dirname, 'src/pages/ruijing/detail/Detail.js'),
        ]
    },

    /*输出到dist文件夹，输出文件名字为bundle.js*/
    output: {
        path: path.join(__dirname, "./out"),
        // filename: 'IndexPage.js',
        // filename: 'Detail.js',
        filename: "SearchProduct.js"

        // filename: 'SearchProduct.js',
        // filename: 'Announcement.js',
    },

    module: {
        rules: [
            {
                test: /\.js$/,
                use: ["babel-loader"],
                include: path.join(__dirname, "src")
            },
            // {
            //     test: /\.css$/,
            //     use: [
            //         MiniCssExtractPlugin.loader,
            //         "css-loader",
            //         "postcss-loader"
            //     ]
            // },
            {
                test: /\.css$/,
                use: ["style-loader", "css-loader", "postcss-loader"]
            },
            {
                test: /\.(png|jpg|gif)$/,
                loader:
                    "url-loader?limit=3000&name=reactimgs/[name][hash:5].[ext]"
            },
            {
                test: /\.scss$/,
                use: [
                    "style-loader",
                    "css-loader",
                    "postcss-loader",
                    "sass-loader",
                    {
                        loader: "sass-resources-loader",
                        options: {
                            resources: ["./src/css/ligw.scss"]
                        }
                    }
                ]
            }
        ]
    },

    resolve: {
        alias: {
            pages: path.join(__dirname, "src/pages"),
            imgs: path.join(__dirname, "src/imgs"),
            utils: path.join(__dirname, "src/utils"),
            "@assets": path.resolve(__dirname, "src/imgs"),
            "@page": path.resolve(__dirname, "src/pages/ruijing"),
            "@ui": path.resolve(__dirname, "src/assets"),
            "@module": path.resolve(__dirname, "src/modules")
        }
    },

    plugins: [
        new UglifyJSPlugin({
            cache: true,
            parallel: true,
            sourceMap: true,
            uglifyOptions: {
                compress: {
                    warnings: false,
                    drop_console: true, //console
                    pure_funcs: ["console.log"] //移除console
                }
            }
        }),
        new webpack.ProvidePlugin(globalConfig)
        // new MiniCssExtractPlugin({
        //     filename: '[name].css',
        // }),
    ]
};
